<template>
	<view class="page">

		<image class="topbg" src="@/static/home/bgtop.png"></image>
		<view class="top">
			<view>三电蜂平台</view>
		</view>
		<!-- 		<view class="addcar bg">
			<view>
				<view class="addcarname">添加车辆</view>
				<view>完善车辆后享受更多服务</view>
			</view>
			<view>
				<u-button customStyle="width:220rpx;height:80rpx;color:#000;font-size:28rpx;" color="#FBCC32"
					shape="circle">添加车辆</u-button>
			</view>
		</view> -->

		<view class="addcar bg"  v-if="!add" @click="$goBack(2,'/bundle/pages/carcircumstance/carcircumstance')">
			<view>
				<view class="addcarname">添加车辆</view>
				<view>完善车辆后享受更多服务</view>
			</view>
			<view>
				<u-button customStyle="width:220rpx;height:80rpx;color:#000;font-size:28rpx;" color="#FBCC32"
					shape="circle">添加车辆</u-button>
			</view>
		</view>
		<view class="addcar" style="background-color:#fff;"  v-else>
			<image style="width: 150rpx;height: 150rpx;" :src="carlist.brandImage"></image>
			<view style="margin-left: 0rpx; width: 300rpx;">
				<view class="addcarname">{{carlist.brandName}}</view>
				<view class="addcot">{{carlist.seriesName}}</view>
			</view>
			<image style="width: 200rpx;height: 100rpx;" :src="carlist.seriesImage"></image>
		</view>

		<view class="bg order">
			<view class="order-name">三电服务</view>
			<view class="list">
				<view class="col" @click="$goBack(2,'/bundle/pages/addmaintenance/addmaintenance')">
					<image src="../../static/home/o.png"></image>
					<view class="writing">维保订单</view>
				</view>
				<!-- 				<view class="col" @click="$goBack(2,'/bundle/pages/addmaintenance/addmaintenance')">
					<image src="../../static/20230328061106_d73a2.jpg"></image>
					<view class="writing">保养订单</view>
				</view> -->
				<!-- <view class="col" @click="$goBack(2,'/bundle/pages/orders/orders')">
					<image src="../../static/home/code.png"></image>
					<view class="writing">卷码核销</view>
				</view> -->
			</view>
		</view>

		<view class="stores">
			<view class="stores-top">
				<view class="stores-name">附近门店</view>
				<view>
					<view style="display: flex; color: #257CFF;"
						@click="$goBack(2,'/bundle/pages/attachmentstores/attachmentstores')">
						<text>全部门店</text>
						<u-icon name="arrow-right" color="#257CFF"></u-icon>
					</view>
				</view>
			</view>
			<view class="distance">距离最近门店约{{storeslist.distanceValue||0}}km，驾车约{{storeslist.distanceValue*3||0}}分钟</view>

			<view class="detail">
				<image class="host" :src="storeslist.img"></image>
				<view class="detail-content" @click="getmap">
					<view class="detail-name">
						{{storeslist.name||"请获取本地位置"}}
					</view>
					<view class="detail-time">
						营业时间：
						{{storeslist.startTime||"00：00：00"}}-
						{{storeslist.endTime||"00：00：00"}}
					</view>
					<view class="detail-map">
						{{storeslist.address||""}}
					</view>
				</view>
				<image @click="map" class="icon" src="../../static/home/map.png"></image>
			</view>

		</view>

		<view class="Progress">
			<view class="Progress-name">工单进度</view>
			<u-steps :current="stepNumber" direction="column" dot activeColor="#FBCC32">
				<u-steps-item current="32" title="提交订单">
					<text class="slot-icon" slot="desc">等待您到店~</text>
				</u-steps-item>
				<u-steps-item title="门店诊断">
					<text class="slot-icon" slot="desc">等待门店确认您爱车的维保项目中~</text>
				</u-steps-item>
				<u-steps-item title="企业审核">
					<view slot="desc">
						<view class="slot-icon">企业管理员对订单内容审核无误后，移交门店施工。</view>
						<view class="progress-content"
							v-if="newOrder.refundNotes!==undefined && newOrder.refundNotes != null && newOrder.refundNotes != ''">
							打回原因：{{newOrder.refundNotes}}
						</view>
					</view>
				</u-steps-item>
				<u-steps-item title="门店施工">
					<text class="slot-icon" slot="desc">维保施工中，等待施工完成，以及您确认维保完成。</text>
				</u-steps-item>
				<u-steps-item title="交车验收">
					<text class="slot-icon" slot="desc">维修完毕，您已签字确认验收车辆。</text>
				</u-steps-item>
			</u-steps>
		</view>
		<view style="margin-top:100rpx; visibility: hidden;">1</view>
	</view>
</template>

<script>
	import {
		apifindCarByUserId
	} from '@/api/car.js'
	import {
		apigetStoreByLocatio
	} from '@/api/shop.js'
	import {
		apiGetNewOrderStepNumberForDriver
	} from '../../api/orders'
	export default {
		data() {
			return {
				value1: 0,
				add: false,
				carlist: '',
				latitude: "",
				longitude: "",
				storeslist: "",
				newOrder: {},
				stepNumber: 0,
				form: {
					name: '哈哈哈'
				}
			}
		},
		onShow() {
			this.getmap()
			this.CarByUser()
			apiGetNewOrderStepNumberForDriver().then(res => {
				this.newOrder = res.data;
				if (this.newOrder.status === 20) {
					this.stepNumber = 0;
				} else if (this.newOrder.status === 30) {
					this.stepNumber = 1;
				} else if (this.newOrder.status === 40) {
					this.stepNumber = 2;
				} else if (this.newOrder.status === 50) {
					this.stepNumber = 3;
				} else {
					this.stepNumber = 4;
				}
			})
		},
		
		created() {
			this.getmap()
			this.CarByUser()
			apiGetNewOrderStepNumberForDriver().then(res => {
				this.newOrder = res.data;
				if (this.newOrder.status === 20) {
					this.stepNumber = 0;
				} else if (this.newOrder.status === 30) {
					this.stepNumber = 1;
				} else if (this.newOrder.status === 40) {
					this.stepNumber = 2;
				} else if (this.newOrder.status === 50) {
					this.stepNumber = 3;
				} else {
					this.stepNumber = 4;
				}
			})
		},


		methods: {
			getmap(){
				let then = this
				uni.getLocation({
					type: 'gcj02', // 坐标系类型
					success: function(res) {
						console.log(res)
						then.latitude = res.latitude; // 维度
						then.longitude = res.longitude; // 经度
						then.StoreByLocatio()
						let setmap = {
							latitude: then.latitude,
							longitude: then.longitude
						}
						uni.setStorageSync("setmap", setmap)
					},
					fail: function(res) {
						console.log('获取定位失败：' + res.errMsg);
					}
				});
			},
			map() {
				wx.openLocation({
					latitude: this.latitude, //维度
					longitude: this.longitude, //经度
					name: this.storeslist.address, //目的地定位名称
					scale: 15, //缩放比例
					address: this.storeslist.address //导航详细地址
				})
			},
			StoreByLocatio() {
				let params = {
					latitude: this.latitude,
					longitude: this.longitude,
					limit: 10,
					radius: 10000
				}

				apigetStoreByLocatio(params).then((res) => {
					uni.setStorageSync("storeslist", res.data)
					this.storeslist = res.data[0]

				})
			},
			CarByUser() {
				let id = uni.getStorageSync('userId')
				apifindCarByUserId(id).then((res) => {

					if (res.data.id != "") {
						uni.setStorageSync('caruser', res.data)
						this.add = true
						this.carlist = res.data
					}
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.addcot {
		overflow: hidden;
		text-overflow: ellipsis;
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.page {
		position: relative;
		background-color: #FFFEF4;
		z-index: 0;
		width: 100vw;
		height: 100vh;

		.topbg {
			z-index: -1;
			position: absolute;
			top: 0;
			width: 100vw;
			height: 424rpx;
		}

		.top {
			padding: 100rpx 40rpx;
			font-size: 34rpx;
			font-weight: 700;
		}

		.bg {

			background: linear-gradient(#FFF3CE 0%, #fff 100%);
		}

		.addcar {
			position: absolute;
			width: 718rpx;
			height: 180rpx;
			box-shadow: 0px 4rpx 8rpx 0px rgba(225, 225, 225, 0.44);
			margin: -80rpx 10rpx 10rpx 17rpx;
			@include flex(row, space-around) font-size: 26rpx;
			padding: 0rpx 20rpx;
			box-sizing: border-box;
			border-radius: 20rpx;

			.addcarname {
				font-size: 28rpx;
				font-weight: 600;
				margin-bottom: 10rpx;
			}
		}
	}

	.order {

		margin: 130rpx 10rpx 20rpx 17rpx;
		padding: 20rpx 20rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		height: 280rpx;

		.order-name {
			font-size: 32rpx;
			font-weight: 600;
		}

		.list {
			margin-top: 18rpx;
			display: flex;
			flex-wrap: wrap;

			.col {
				margin: 18rpx 30rpx 0rpx 20rpx;
				margin-top: 18rpx;
				width: 120rpx;
				text-align: center;

				image {
					width: 88rpx;
					height: 88rpx;

				}

				.writing {
					margin-top: 10rpx;
					font-size: 28rpx;

				}
			}
		}
	}

	.stores {
		box-shadow: 0px 4rpx 8rpx 0px rgba(225, 225, 225, 0.44);
		margin: 10rpx 10rpx 20rpx 17rpx;
		padding: 20rpx 20rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		height: 340rpx;
		background-color: #fff;

		.stores-top {
			@include flex(row, space-between, center);
			font-size: 28rpx;
		}

		.stores-name {
			font-size: 32rpx;
			font-weight: 600;

		}

		.distance {
			background-color: #f1f1f1;
			margin: 10rpx;
			padding: 10rpx 20rpx;
			font-size: 26rpx;
			border-radius: 30rpx;
			color: #949494;
		}

		.detail {
			margin-top: 25rpx;

			@include flex(row, space-between, center) .detail-content {
				width: 380rpx;
				font-size: 24rpx;
				margin-top: -40rpx;

				.detail-name {
					font-size: 32rpx;
					font-weight: 600;
					margin-bottom: 6rpx;
				}

				.detail-time {
					font-size: 24rpx;
					color: #949494;
					margin-bottom: 6rpx;
				}
			}
		}

		.host {
			height: 160rpx;
			width: 160rpx;
		}

		.icon {
			height: 48rpx;
			width: 48rpx;
			margin-right: 10rpx;
		}
	}

	.Progress {
		box-shadow: 0px 4rpx 8rpx 0px rgba(225, 225, 225, 0.44);
		margin: 10rpx 10rpx 130rpx 17rpx;
		padding: 20rpx 20rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		height: 560rpx;
		background-color: #fff;

		.Progress-name {
			font-size: 32rpx;
			font-weight: 600;
			margin-bottom: 10rpx;
		}

		.slot-icon {

			margin-top: 10rpx;
			font-size: 24rpx;
			color: #939393;
		}
	}

	::v-deep .u-text__value {
		font-size: 32rpx !important;
		font-weight: 600 !important;
		color: #000 !important;
	}

	::v-deep .u-steps-item__line {
		height: 130rpx !important;
	}

	::v-deep .u-steps-item--column {
		margin-bottom: 50rpx;
	}

	::v-deep .u-steps-item--column:nth-child(2) .u-steps-item__line {
		height: 200rpx !important;
	}

	.progress-content {
		margin-top: 10rpx;
		font-size: 24rpx;
		color: red;
		width: 600rpx;
		background-color: #F8F8F8;
		padding: 10rpx;
	}
</style>